#include "UIRenderer.h"

namespace TUMAR { namespace Render {
	UIRenderer::UIRenderer() : height(480), width(640)
	{
	}

	UIRenderer::~UIRenderer(void)
	{
	}

	void UIRenderer::Resize(int width, int height)
	{
		this->width = width;
		this->height = height;

	}

	void UIRenderer::Init(void)
	{
		this->logo = LoadTexture("countryroads_logo.png");
	}

	void UIRenderer::Render(void)
	{
		
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();

		glLoadIdentity();
		gluOrtho2D(0, this->width, 0, this->height);
		
		{
			glMatrixMode(GL_MODELVIEW);
			glPushMatrix();	

			int y_Offset=0;
			//int y_Offset=10;

			//glTranslatef(0,y_Offset,0);
			//displayString("Hallo Lucky", 0,0,0, 3, 20);
			////displayString("Hallo Lucky", 1,1,1, 2, 19);
			//displayString("Hallo Lucky", 1,1,1, 1, 18);
			//displayString("Hallo Lucky", 1,1,1, 0, 17);

			

			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, logo);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

			//logo has a aspect-ratio of 8.8
			
			glTranslatef(this->width/6+this->width*0.03, this->height-y_Offset-this->width/(3*8.8),0);			
			
			glScalef(this->width/3,this->width/(3*8.8),0);

			glColor3f(1, 1, 1);
			glBegin(GL_QUADS);

			glTexCoord2f(0.0f, 0.0f);
			glVertex3f(-0.5, -0.5, 0);
			glTexCoord2f(1.0f, 0.0f);
			glVertex3f( 0.5, -0.5, 0);
			glTexCoord2f(1.0f, 1.0f);
			glVertex3f( 0.5,  0.5, 0);
			glTexCoord2f(0.0f, 1.0f);
			glVertex3f(-0.5,  0.5, 0);

			glEnd();

			glDisable(GL_TEXTURE_2D);


			glPopMatrix();
		}

		glMatrixMode(GL_PROJECTION);
		glPopMatrix();
	}

	void UIRenderer::displayString(char string[], float r, float g, float b, int cx, int y)
	{
		glColor3f(r, g, b); //font color

		int x = cx; /*- ((strlen(string)*9)/2)*/;
		y=y-7; 

		for(unsigned int i=0; i !=strlen(string); ++i)
		{
			glRasterPos3f(x, y, 0);
			glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, string[i]);

			x=x+24;
		}
	}

	/*void UIRenderer::OnGameUpdated(const Game* game)
	{
		this->game=game;

		
	}*/

}}
